<template>
  <div v-loading="dialogVisiblePayLoading">
    <div class="area-header">
      <span class="area-header-title">{{ actTitle }}</span>
    </div>
    <el-form ref="form" :model="form" :rules="rules" style="position: unset;">
      <el-row>
        <el-table tooltip-effect="darkTable" :data="form.investorList" border class="nowrapTable formTable">
          <el-table-column :label="$t('主体名称')" align="center" min-width="180" fixed="left">
            <template slot="header" slot-scope="{}">
              <i style="color: red;">*</i>
              <span>{{ $t('主体名称') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'investorList.' + scope.$index + '.investorId'" :rules="investorListRules.investorId">
                <el-select v-model="scope.row.investorId" @change="changeInvest($event, scope.$index)">
                  <el-option
                    v-for="dict in mainBodySelectOption"
                    :key="dict.investorId"
                    :label="$t(dict.investorName)"
                    :value="dict.investorId"
                  />
                </el-select>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('收款方')" align="center" :min-width="180">
            <template slot="header" slot-scope="{}">
              <span>{{ $t('收款方') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'investorList.' + scope.$index + '.payee'" :rules="investorListRules.payee">
                <el-select v-model="scope.row.payee" :placeholder="$t('收款方')">
                  <el-option
                    v-for="dict in scope.row.dealPaymentBeneficiaryOption"
                    :key="dict.payee"
                    :label="$t(dict.payee)"
                    :value="dict.payee"
                  />
                </el-select>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('划款时间')" align="center" :min-width="180">
            <template slot="header" slot-scope="{}">
              <i style="color: red;">*</i>
              <span>{{ $t('划款时间') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'investorList.' + scope.$index + '.actualPaymentTime'"
                :rules="investorListRules.actualPaymentTime"
              >
                <DatePicker v-model="scope.row.actualPaymentTime" clearable :placeholder="$t('划款时间')" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column align="center" :min-width="isShowInvestorCurrency ? 240 : 180">
            <template slot="header" slot-scope="{}">
              <i style="color: red;">*</i>
              <span>{{ $t('实际划款金额') }}{{ $t('金额单位') }} - ({{ formatCurrency(parentCurrency) }})</span>
              <el-tooltip :content="$t('合同中拟定的币种金额')">
                <i class="el-icon-question" />
              </el-tooltip>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'investorList.' + scope.$index + '.actualPaymentMoney'"
                :rules="investorListRules.actualPaymentMoney"
              >
                <Money
                  v-model="scope.row.actualPaymentMoney"
                  unit="w"
                  :placeholder="$t('请输入金额', 'w')"
                  @change="
                    rateAmountCalculate(scope.row.actualPaymentMoney, scope.row.exchangeRate, scope.$index);
                    getExchangeRate(scope.row.actualPaymentMoney, scope.row.transferAmount, scope.row.exchangeRate, scope.$index)
                    changeDealCurrency(scope.row, scope.$index)
                  "
                />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column v-if="isShowInvestorCurrency" align="center" min-width="180">
            <template slot="header" slot-scope="{}">
              <i style="color: red;">*</i>
              <span>{{ $t('主体币种') }}</span>
              <el-tooltip :content="$t('当前主体的币种')">
                <i class="el-icon-question" />
              </el-tooltip>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'investorList.' + scope.$index + '.currency'" :rules="investorListRules.currency">
                <el-select v-model="scope.row.currency" :disabled="scope.row.currency !== undefined && scope.row.currency !== null && scope.row.currency !== ''">
                  <el-option
                    v-for="dict in currencyOptions"
                    :key="dict.id"
                    :label="$t(dict.dictLabel)"
                    :value="dict.dictValue"
                  />
                </el-select>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column v-if="isShowInvestorCurrency" align="center" :min-width="showDetails ? 420 : 170">
            <template slot="header" slot-scope="{}">
              <i style="color: red;">*</i>
              <span>{{ $t('转换主体币种汇率') }} {{ $t('(元)') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'investorList.' + scope.$index + '.exchangeRate'"
                :rules="investorListRules.exchangeRate"
              >
                <span v-if="showDetails">{{ $t('合同币种') }}<span style="color:#46a6ff">{{ formatCurrency(parentCurrency) }}</span>{{ $t('对') }}{{ $t('当前主体币种') }}<span style="color: #46a6ff">{{ formatCurrency(scope.row.currency) }}</span>{{ $t('的') }}{{ $t('汇率') }}:</span>
                <el-input-number
                  v-model="scope.row.exchangeRate"
                  :max="999999999"
                  :min="0"
                  :precision="6"
                  :disabled="scope.row.currency === parentCurrency"
                  :placeholder="scope.row.placeholder"
                  :controls="false"
                  @change="rateAmountCalculate(scope.row.actualPaymentMoney, scope.row.exchangeRate, scope.$index)"
                />
                <!--
                <el-tooltip :content="$t('使用') + scope.row.placeholder" placement="right">
                  <el-button
                    v-if="scope.row.placeholder !== undefined && scope.row.placeholder !== null && scope.row.placeholder !== ''"
                    class="el-icon-document-copy"
                    size="small"
                    type="text"
                    style="color: rgb(143 143 143) !important;cursor: pointer;position: absolute;float: right;right: 0;font-size: 16px;"
                    @click="inputPlaceholder(scope.$index, scope.row.placeholder)"
                  />
                </el-tooltip>
                -->
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column v-if="isShowInvestorCurrency" align="center" :min-width="showDetails ? 210 : 170">
            <template slot="header" slot-scope="{}">
              <i style="color: red;">*</i>
              <span>{{ $t('主体划款金额') }}{{ $t('金额单位') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'investorList.' + scope.$index + '.transferAmount'"
                :rules="investorListRules.transferAmount"
              >
                <Money
                  v-model="scope.row.transferAmount"
                  unit="w"
                  @change="getExchangeRate(scope.row.actualPaymentMoney, scope.row.transferAmount, scope.row.exchangeRate, scope.$index)"
                />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column v-if="isShowDealCurrency" align="center" min-width="180">
            <template slot="header" slot-scope="{}">
              <i style="color: red;">*</i>
              <span>{{ $t('项目币种') }}</span>
            </template>
            <template slot-scope="{}">
              <el-select v-model="dealBaseData.currency" disabled>
                <el-option
                  v-for="dict in currencyOptions"
                  :key="dict.id"
                  :label="$t(dict.dictLabel)"
                  :value="dict.dictValue"
                />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column v-if="isShowDealCurrency" align="center" :min-width="showDetails ? 420 : 170">
            <template slot="header" slot-scope="{}">
              <i style="color: red;">*</i>
              <span>{{ $t('转换项目币种汇率') }} {{ $t('(元)') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'investorList.' + scope.$index + '.dealCurrencyRate'"
                :rules="investorListRules.dealCurrencyRate"
              >
                <span v-if="showDetails">{{ $t('合同币种') }}<span style="color: #46a6ff">{{ formatCurrency(parentCurrency) }}</span>{{ $t('对') }}{{ $t('项目币种') }}<span style="color: #46a6ff">{{ formatCurrency(dealBaseData.currency) }}</span>{{ $t('的') }}{{ $t('汇率') }}:</span>
                <el-input-number
                  v-model="scope.row.dealCurrencyRate"
                  :max="999999999"
                  :min="0"
                  :precision="6"
                  :placeholder="scope.row.dealPlaceholder"
                  :controls="false"
                  @change="changeDealCurrency(scope.row, scope.$index)"
                />
                <!--
                <el-tooltip :content="$t('使用') + scope.row.dealPlaceholder" placement="right">
                  <el-button
                    v-if="scope.row.dealPlaceholder !== undefined && scope.row.dealPlaceholder !== null && scope.row.dealPlaceholder !== ''"
                    class="el-icon-document-copy"
                    size="small"
                    type="text"
                    style="color: rgb(143 143 143) !important;cursor: pointer;position: absolute;float: right;right: 0;font-size: 16px;"
                    @click="inputDealPlaceholder(scope.$index, scope.row.dealPlaceholder)"
                  />
                </el-tooltip>
                -->
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column v-if="isShowDealCurrency" align="center" :min-width="showDetails ? 210 : 170">
            <template slot="header" slot-scope="{}">
              <i style="color: red;">*</i>
              <span>{{ $t('项目币种金额') }}{{ $t('金额单位') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'investorList.' + scope.$index + '.dealCurrencyAmount'"
                :rules="investorListRules.dealCurrencyAmount"
              >
                <Money
                  v-model="scope.row.dealCurrencyAmount"
                  unit="w"
                />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('划款凭证')" align="center" width="200">
            <template slot-scope="scope">
              <div v-if="scope.row.fileList !== null && scope.row.fileList !== '' && scope.row.fileList !== undefined && scope.row.fileList.length > 0" style="width: 100%;">
                <el-dropdown>
                  <span :title="scope.row.fileList[0].name" style="cursor: pointer;width: 180px !important;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;display: block;font-size: 13px;">
                    <i class="el-icon-paperclip" style="margin-right:5px;" />{{ scope.row.fileList[0].name }}
                  </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item com @click.native="onlinePreview(scope.row.fileList[0])">{{ $t('预览') }}</el-dropdown-item>
                    <el-dropdown-item @click.native="downLoadFileOpens(scope.row.fileList[0].id)">{{ $t('下载') }}</el-dropdown-item>
                    <el-dropdown-item @click.native="deleteFile(scope.row)">{{ $t('删除') }}</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </div>
              <div v-if="scope.row.fileList === null || scope.row.fileList === '' || scope.row.fileList === undefined || scope.row.fileList.length <= 0">
                <uploadSingle
                  ref="uploadSingle"
                  :data-type="'deal_payment_list'"
                  :file-config-code="'deal_payment_' + dealType"
                  upload-style="color: #fff;background-color: #67c23a;cursor: pointer;border-radius: 4px;border: 1px solid #67c23a;width: 65px;height: 25px;line-height: 1.25;"
                  :data-table-row-num="scope.$index"
                  :upload-btn-name="$t('上传')"
                  @onFileSuccess="onFileSuccess"
                  @okPostUploadHook="okPostUploadHook(scope.$index)"
                />
              </div>
            </template>
          </el-table-column>
          <el-table-column :label="$t('操作')" fixed="right" align="center" width="80" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="small"
                type="text"
                icon="el-icon-deleted"
                @click="delHandler(scope.$index, scope.row)"
              >{{ $t('删除') }}</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="tol">
          <el-button type="primary" icon="el-icon-plus" size="mini" @click="addPayment">{{ $t("添加") }}</el-button>
          <el-checkbox v-if="isShowInvestorCurrency || isShowDealCurrency" v-model="showDetails" style="float: right;margin-right: 10px;">{{ $t('展示描述') }}</el-checkbox>
        </div>
      </el-row>
    </el-form>
    <div v-if="!actTaskShowTimeBtn" slot="footer" class="dialog-footer">
      <el-button @click="closePage">{{ $t('取消') }}</el-button>
      <el-button type="warning" @click="submitForm(false)">{{ $t('暂存') }}</el-button>
      <el-button type="primary" :disabled="disabledUploading" @click="submitForm(true)">{{ $t('保存') }}</el-button>
    </div>
    <div v-if="actTaskShowTimeBtn" slot="footer" class="dialog-footer">
      <el-button @click="closePage">{{ $t('取消') }}</el-button>
      <el-button type="primary" @click="submitForm(false)">{{ $t('确定') }}</el-button>
    </div>
    <OnlinePreview ref="OnlinePreview" />
  </div>
</template>
<script>
import uploadSingle from '@/components/File/Upload/single.vue'
import { getOaPayment } from '@/api/oa/payment/oaPayment'
import {
  autoMaintenancePaymentStatus,
  deletePaymentMaintainByIdList,
  getDealPayment,
  obtainTemporaryStorage,
  temporaryStorageInvest
} from '@/api/deal/payment/dealPayment'
import { downLoadFileOpen } from '@/utils/zipdownload'
import { getDealBase } from '@/api/base/deal/dealBase'
import { getWebRate } from '@/api/deal/investment/dealInvestment'

export default {
  components: {
    uploadSingle
  },
  props: {
    dialogVisiblePayMoneyValue: {
      type: String,
      default: ''
    },
    dialogVisiblePayTimeValue: {
      type: String,
      default: ''
    },
    actTitle: {
      type: String,
      default: ''
    }
  },
  data() {
    const checkRate = (rule, value, callback) => {
      if (value === undefined || value === null || value === '') {
        callback(new Error(this.$t('必填信息')))
      } else if (value === 0) {
        callback(new Error(this.$t('汇率不能为0')))
      } else {
        callback()
      }
    }
    return {
      form: {
        investorList: []
      },
      type: '',
      // 划款币种
      currencyOptions: [],
      // 主体字典下拉列表
      mainBodySelectOption: [],
      // 遮罩层
      dialogVisiblePayLoading: false,
      // 保存后🏆删除的数据
      saveAfterDeleteByIdList: [],
      disabledUploading: false,
      // 主体
      rules: {},
      investorListRules: {
        investorId: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        // payee: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        actualPaymentTime: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        actualPaymentMoney: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        currency: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        exchangeRate: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        transferAmount: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        dealCurrencyRate: [{ required: true, validator: checkRate, trigger: ['blur', 'change'] }]
      },
      dealType: '',
      parentCurrency: '',
      // 收款字典Map
      payeeOptionMap: undefined,
      // 是否展示项目币种及汇率
      isShowDealCurrency: true,
      // 是否展示主体币种及汇率
      isShowInvestorCurrency: false,
      dealBaseData: undefined,
      showDetails: false,
      actTaskShowTimeBtn: false
    }
  },
  created() {
    // 划款币种
    this.getDicts('currency').then(response => {
      this.currencyOptions = response.data
    })
  },
  methods: {
    init(data, type) {
      this.type = type
      this.form.investorList = []
      this.dialogVisiblePayLoading = true
      this.dealType = data.dealType
      this.actTaskShowTimeBtn = false
      var _this = this
      var dealId = _this.$route.query.id
      if (dealId === undefined) {
        dealId = data.dealId
      }
      getDealBase(dealId).then(res => {
        _this.dealBaseData = res.data
        if (type === 'oa_payment') {
          getOaPayment(data.id).then(response => {
            _this.form = response.data
            _this.getSelectMain()
            _this.getTemporaryData()
          })
        } else if (type === 'deal_payment') {
          getDealPayment(data.id).then(response => {
            _this.form = response.data
            // 获取收款方字典Map
            _this.getDictOptionMapArr()
            _this.getSelectMain()
            _this.initSetData()
            _this.getTemporaryData()
          })
        } else {
          _this.dialogVisiblePayLoading = false
        }
        if (_this.dealBaseData.currency === _this.parentCurrency) {
          _this.isShowDealCurrency = false
        }
      })
    },
    initSetData() {
      this.form.investorList.forEach(item => {
        item.actualPaymentMoney = item.amount
        item.transferAmount = item.rateAmount
      })
    },
    // 获取收款方字典Map
    getDictOptionMapArr() {
      this.payeeOptionMap = new Map()
      this.form.investorList && this.form.investorList.forEach(item => {
        if (this.payeeOptionMap.get(item.investorId) !== undefined) {
          if (item.payee !== '' && item.payee !== undefined && item.payee !== null) {
            this.payeeOptionMap.get(item.investorId).push({ payee: item.payee })
          }
        } else {
          var arr = []
          if (item.payee !== '' && item.payee !== undefined && item.payee !== null) {
            arr.push({ payee: item.payee })
          }
          this.payeeOptionMap.set(item.investorId, arr)
        }
      })
    },
    async initCurrency() {
      this.form.investorList && this.form.investorList.forEach((item, index) => {
        if (item.currency === this.parentCurrency) {
          item.exchangeRate = 1
        }
        this.loadRate(index)
      })
    },
    // 获取暂存数据
    getTemporaryData() {
      obtainTemporaryStorage(this.form.id).then(response => {
        if (response.code === 200 && response.data !== null && response.data.length > 0) {
          this.form.investorList = response.data
          this.form.investorList.forEach(item => {
            item.actualPaymentTime = item.investorTime
            item.actualPaymentMoney = item.money
            if (this.payeeOptionMap.get(item.investorId) !== undefined) {
              item.dealPaymentBeneficiaryOption = this.payeeOptionMap.get(item.investorId)
            }
          })
        }
        this.dialogVisiblePayLoading = false
      })
    },
    // 获取主体下拉字典
    getSelectMain() {
      if (this.form.investorList !== undefined && this.form.investorList !== null && this.form.investorList !== '' && this.form.investorList.length > 0) {
        console.log('zhuti')
        this.form.investorList.forEach(item => {
          // 是否显示主体多币种
          if (item.currency !== this.parentCurrency && !this.isShowInvestorCurrency) {
            this.isShowInvestorCurrency = true
          }
          const temp = this.mainBodySelectOption.find(obj => obj.investorId === item.investorId)
          if (!temp) {
            this.mainBodySelectOption.push(item)
          }
        })
      }
    },
    // 选中主体后获取主体信息
    changeInvest(id, index) {
      const find = this.mainBodySelectOption.find(obj => obj.investorId === id)
      if (find) {
        this.form.investorList[index].currency = find.currency
        if (find.currency === this.parentCurrency) {
          this.form.investorList[index].exchangeRate = 1
        }
        if (this.payeeOptionMap.get(id) !== undefined) {
          this.form.investorList[index].dealPaymentBeneficiaryOption = this.payeeOptionMap.get(id)
        }
      }
      // 加载汇率
      this.loadRate(index)
    },
    async loadRate(index) {
      const sourceCurrency = this.form.investorList[index].currency
      if (this.isShowInvestorCurrency) {
        await getWebRate(this.parentCurrency, sourceCurrency, this.form.investorList[index].actualPaymentTime).then(response => {
          this.$set(this.form.investorList[index], 'placeholder', this.$t('汇率参考') + ': ' + response.data)
          this.$set(this.form.investorList[index], 'exchangeRate', response.data)
          this.$forceUpdate()
        })
      }
      if (this.isShowDealCurrency) {
        await getWebRate(this.parentCurrency, this.dealBaseData.currency, this.form.investorList[index].actualPaymentTime).then(response => {
          this.$set(this.form.investorList[index], 'dealPlaceholder', this.$t('汇率参考') + ': ' + response.data)
          this.$set(this.form.investorList[index], 'dealCurrencyRate', response.data)
          this.$forceUpdate()
        })
      }
    },
    inputPlaceholder(index, val) {
      if (val !== undefined && val !== null && val !== '') {
        val = val.replaceAll('汇率参考', '').replaceAll(':', '').trim()
        this.$set(this.form.investorList[index], 'exchangeRate', val)
        this.$forceUpdate()
      }
    },
    inputDealPlaceholder(index, val) {
      if (val !== undefined && val !== null && val !== '') {
        val = val.replaceAll('汇率参考', '').replaceAll(':', '').trim()
        this.$set(this.form.investorList[index], 'dealCurrencyRate', val)
        this.$forceUpdate()
      }
    },
    // 添加行
    addPayment() {
      const row = {
        id: undefined,
        payee: undefined,
        currency: undefined,
        investorId: undefined,
        actualPaymentTime: undefined,
        actualPaymentMoney: undefined,
        exchangeRate: undefined,
        transferAmount: undefined,
        dealCurrencyRate: undefined,
        dealCurrencyAmount: undefined,
        fileList: []
      }
      if (!(this.form.investorList instanceof Array)) {
        this.$set(this.form, 'investorList', [])
      }
      this.$nextTick(() => {
        this.form.investorList.push(row)
        this.$forceUpdate()
      })
    },
    // 删除行
    delHandler(index, row) {
      if (row.id) {
        this.saveAfterDeleteByIdList.push(row.id)
      }
      this.form.investorList.splice(index, 1)
      this.msgInfo(this.$t('已删除, 保存后生效!'))
    },
    delChoiceHandler() {
      console.log(this.saveAfterDeleteByIdList)
      if (!this.isEmpty(this.saveAfterDeleteByIdList)) {
        deletePaymentMaintainByIdList({ idList: this.saveAfterDeleteByIdList.join(',') }).then(() => {
          this.saveAfterDeleteByIdList = []
        })
      }
    },
    // 暂存
    submitForm(flag) {
      this.$refs['form'].validate(valid => {
        if (valid) {
            this.dialogVisiblePayLoading = true
            this.form.investorList.forEach(item => {
              item.dealId = this.form.dealId
              item.paymentId = this.form.id
              if (this.type === 'oa_payment') {
                item.type = 'oa'
              } else {
                item.type = 'deal'
              }
            })
            console.log(this.form.investorList)
            // 主体汇率
            if (!this.isShowInvestorCurrency) {
              this.form.investorList.forEach(item => {
                item.transferAmount = item.actualPaymentMoney
                item.exchangeRate = 1
                item.currency = this.parentCurrency
              })
            }
            // 给隐藏的汇率及金额附上默认值   -    项目币种与合同同步到划款的币种相同
            if (!this.isShowDealCurrency) {
              this.form.investorList.forEach(item => {
                item.dealCurrencyRate = 1
                item.dealCurrencyAmount = item.actualPaymentMoney
              })
            }
            temporaryStorageInvest(this.form.investorList).then(response => {
              if (response.code === 200) {
                if (flag) {
                  this.updatePayTimeSuccess()
                } else {
                  if (!this.actTaskShowTimeBtn) {
                    this.msgSuccess(this.$t('暂存成功!'))
                    this.dialogVisiblePayLoading = false
                  } else {
                    // 将主表的是否维护付款时间记录上
                    autoMaintenancePaymentStatus(this.form.id, 'Y').then(response => {
                      console.log(response)
                      this.msgSuccess(this.$t('操作成功!'))
                      this.dialogVisiblePayLoading = false
                      this.closePage()
                    }).catch(() => {
                      this.msgSuccess(this.$t('操作失败!'))
                      this.dialogVisiblePayLoading = false
                    })
                  }
                }
              } else {
                this.msgError(this.$t('暂存失败!'))
                this.dialogVisiblePayLoading = false
              }
            })
        }
      })
    },
    // 提交维护划款时间,
    updatePayTimeSuccess() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.dialogVisiblePayLoading = true
          var investorList = []
          var data = { id: this.form.id }
          if (this.type === 'oa_payment') {
            if (this.form.investorList !== undefined && this.form.investorList.length > 0) {
              this.form.investorList.some(item => {
                investorList.push({
                  id: item.id,
                  paymentId: this.form.id,
                  currency: item.currency,
                  exchangeRate: item.exchangeRate,
                  investorId: item.investorId,
                  actualPaymentTime: item.actualPaymentTime,
                  actualPaymentMoney: item.actualPaymentMoney,
                  transferAmount: item.transferAmount,
                  dealCurrencyAmount: item.dealCurrencyAmount,
                  dealCurrencyRate: item.dealCurrencyRate
                })
              })
              data.investorList = investorList
            }
          }
          if (this.type === 'deal_payment') {
            if (this.form.investorList !== undefined && this.form.investorList.length > 0) {
              this.form.investorList.some(item => {
                investorList.push({
                  id: item.id,
                  payee: item.payee,
                  paymentId: this.form.id,
                  currency: item.currency,
                  exchangeRate: item.exchangeRate,
                  investorId: item.investorId,
                  actualPaymentTime: item.actualPaymentTime,
                  actualPaymentMoney: item.actualPaymentMoney,
                  transferAmount: item.transferAmount,
                  dealCurrencyAmount: item.dealCurrencyAmount,
                  dealCurrencyRate: item.dealCurrencyRate
                })
              })
              data.investorList = investorList
            }
          }
          this.$emit('updatePayTimeSuccess', data, (result) => {
            if (result) {
              console.log('维护成功, 删除数据')
              // 删除被标记的记录的数据
              this.delChoiceHandler()
            } else {
              console.log('维护失败, 不删除')
            }
          })
        }
      })
    },
    closePage() {
      this.$parent.$parent.MaintainPaymentInforLoading = false
    },
    // 预览附件
    onlinePreview(row) {
      this.$refs.OnlinePreview.onlinePreviewFile(row.id)
    },
    downLoadFileOpens(id) {
      downLoadFileOpen(id)
    },
    deleteFile(row) {
      this.loading = true
      if (row.fileList && row.fileList[0] && row.fileList[0].id) {
        if (this.isEmpty(row.delFileList)) {
          row.delFileList = []
        }
        row.delFileList.push(row.fileList[0])
        row.fileList = []
      } else {
        row.fileList = null
      }
    },
    // 汇率金额之间自动计算 根据划款金额和汇率计算划款金额
    // 实际划款金额 actualPaymentMoney
    // 汇率 exchangeRate
    // 划款 金额 transferAmount
    rateAmountCalculate(rateAmount, rate, index) {
      if (rateAmount !== undefined && rateAmount !== null && rateAmount !== '' && !isNaN(parseFloat(rateAmount)) && rate !== undefined && rate !== null && rate !== '' && !isNaN(parseFloat(rate))) {
        this.form.investorList[index].transferAmount = (parseFloat(rateAmount) * parseFloat(rate)).toFixed(6)
        this.form.investorList[index].transferAmount = Number(this.form.investorList[index].transferAmount)
      }
    },
    // 根据划款金额和划款金额计算汇率
    getExchangeRate(money, rateAmount, rate, index) {
      if (rateAmount !== undefined && rateAmount !== null && rateAmount !== '' && !isNaN(parseFloat(rateAmount)) && money !== undefined && money !== null && money !== '' && !isNaN(parseFloat(money))) {
        if (parseFloat(money) !== 0 && parseFloat(rateAmount) !== 0 && (rate === undefined || rate === null || rate === '' || rate === 0)) {
          this.form.investorList[index].exchangeRate = (parseFloat(rateAmount) / parseFloat(money)).toFixed(6)
        }
      }
    },
    changeDealCurrency(row, index) {
      var actualPaymentMoney = this.formatNum(row.actualPaymentMoney)
      var dealCurrencyRate = this.formatNum(row.dealCurrencyRate)
      this.form.investorList[index].dealCurrencyAmount = actualPaymentMoney * dealCurrencyRate
    },
    formatNum(val) {
      if (val !== undefined && val !== null && val !== '' && !isNaN(val)) {
        if (Number(val)) {
          return parseFloat(val)
        } else {
          return 0
        }
      } else {
        return 0
      }
    },
    formatCurrency(val) {
      const currency = this.currencyOptions.find(obj => obj.dictValue === val)
      if (currency) {
        return currency.dictLabel
      }
      return val
    },
    onFileSuccess(that, file, rowIndex) {
      this.$nextTick(() => {
        this.form.investorList[rowIndex].fileList = [{ id: file.fileId, name: file.fileName }]
      })
      this.disabledUploading = false
    },
    formatRateMoney(row) {
      const money = row.actualPaymentMoney
      const rate = row.exchangeRate
      if (money !== undefined && money !== null && money !== '' && rate !== undefined && rate !== null && rate !== '') {
        return (parseFloat(money) * parseFloat(rate)).toFixed(6)
      }
      return 0
    },
    okPostUploadHook() {
      this.disabledUploading = true
    }
  }
}
</script>
<style lang="scss" scoped>
.el-form-item {
  margin-bottom: 0px;
}
.customMoneyMaintain {
  -webkit-appearance: none;
  background-color: #F5F7FA;
  background-image: none;
  border-radius: 4px;
  border: 1px solid #DCDFE6;
  box-sizing: border-box;
  color: #606266;
  display: inline-block;
  font-size: inherit;
  height: 40px;
  line-height: 40px;
  outline: none;
  padding: 0 15px;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  width: 100%;
  text-align: left;
}

///deep/ .el-table td.el-table__cell div {
//  float: right;
//  .el-form-item__error {
//    width: 100%;
//  }
//}
/deep/ .el-table .el-table__body tbody tr td.fixed-width:last-child .cell {
  float: none;
}
</style>
